home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 November / CHIP Kasım 1996.iso / ms / visualj / vjtrialb.exe / RCDATA / CABINET / MFCAPWZ.DLL / TEMPLATE / VIEW.CPP < prev    next >
C/C++ Source or Header  |  1996-07-31  |  12KB  |  441 lines

  1. // $$view_ifile$$.cpp : implementation of the $$VIEW_CLASS$$ class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "$$root$$.h"
  6.  
  7. $$IF(CRecordView || CDaoRecordView)
  8. #include "$$recset_hfile$$.h"
  9. $$ENDIF
  10. #include "$$doc_hfile$$.h"
  11. $$IF(CONTAINER || CONTAINER_SERVER)
  12. #include "$$cntritem_hfile$$.h"
  13. $$ENDIF
  14. #include "$$view_hfile$$.h"
  15.  
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // $$VIEW_CLASS$$
  24.  
  25. IMPLEMENT_DYNCREATE($$VIEW_CLASS$$, $$VIEW_BASE_CLASS$$)
  26.  
  27. BEGIN_MESSAGE_MAP($$VIEW_CLASS$$, $$VIEW_BASE_CLASS$$)
  28.     //{{AFX_MSG_MAP($$VIEW_CLASS$$)
  29. $$IF(VERBOSE)
  30.         // NOTE - the ClassWizard will add and remove mapping macros here.
  31.         //    DO NOT EDIT what you see in these blocks of generated code!
  32. $$ENDIF
  33. $$IF(CONTAINER || CONTAINER_SERVER)
  34. $$IF(!CRichEditView)
  35.     ON_WM_SETFOCUS()
  36.     ON_WM_SIZE()
  37.     ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
  38.     ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
  39. $$ENDIF //!CRichEditView
  40. $$ENDIF //CONTAINERS
  41. $$IF(MINI_SERVER || FULL_SERVER || CONTAINER_SERVER)
  42.     ON_COMMAND(ID_CANCEL_EDIT_SRVR, OnCancelEditSrvr)
  43. $$ENDIF
  44.     //}}AFX_MSG_MAP
  45. $$IF(PRINT)
  46.     // Standard printing commands
  47.     ON_COMMAND(ID_FILE_PRINT, $$VIEW_BASE_CLASS$$::OnFilePrint)
  48.     ON_COMMAND(ID_FILE_PRINT_DIRECT, $$VIEW_BASE_CLASS$$::OnFilePrint)
  49.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, $$VIEW_BASE_CLASS$$::OnFilePrintPreview)
  50. $$ENDIF //PRINT
  51. END_MESSAGE_MAP()
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // $$VIEW_CLASS$$ construction/destruction
  55.  
  56. $$VIEW_CLASS$$::$$VIEW_CLASS$$()
  57. $$IF(CFormView || CRecordView || CDaoRecordView)
  58.     : $$VIEW_BASE_CLASS$$($$VIEW_CLASS$$::IDD)
  59. $$ENDIF
  60. {
  61. $$IF(CFormView || CRecordView || CDaoRecordView)
  62.     //{{AFX_DATA_INIT($$VIEW_CLASS$$)
  63.         // NOTE: the ClassWizard will add member initialization here
  64. $$IF(CRecordView || CDaoRecordView)
  65.     m_pSet = NULL;
  66. $$ENDIF
  67.     //}}AFX_DATA_INIT
  68. $$ENDIF
  69. $$IF(CONTAINER || CONTAINER_SERVER)
  70. $$IF(!CRichEditView)
  71.     m_pSelection = NULL;
  72. $$ENDIF //!CRichEditView
  73. $$ENDIF //CONTAINERS
  74. $$IF(VERBOSE)
  75.     // TODO: add construction code here
  76.  
  77. $$ENDIF
  78. }
  79.  
  80. $$VIEW_CLASS$$::~$$VIEW_CLASS$$()
  81. {
  82. }
  83. $$IF(CFormView || CRecordView || CDaoRecordView)
  84.  
  85. void $$VIEW_CLASS$$::DoDataExchange(CDataExchange* pDX)
  86. {
  87.     $$VIEW_BASE_CLASS$$::DoDataExchange(pDX);
  88.     //{{AFX_DATA_MAP($$VIEW_CLASS$$)
  89.         // NOTE: the ClassWizard will add DDX and DDV calls here
  90.     //}}AFX_DATA_MAP
  91. }
  92. $$ENDIF
  93.  
  94. BOOL $$VIEW_CLASS$$::PreCreateWindow(CREATESTRUCT& cs)
  95. {
  96. $$IF(VERBOSE)
  97.     // TODO: Modify the Window class or styles here by modifying
  98.     //  the CREATESTRUCT cs
  99.  
  100. $$ENDIF //VERBOSE
  101. $$IF(CEditView)
  102.     BOOL bPreCreated = CEditView::PreCreateWindow(cs);
  103.     cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);    // Enable word-wrapping
  104.  
  105.     return bPreCreated;
  106. $$ELSE //!CEditView
  107.     return $$VIEW_BASE_CLASS$$::PreCreateWindow(cs);
  108. $$ENDIF //CEditView
  109. }
  110. $$IF(CFormView || CRecordView || CDaoRecordView)
  111. $$ELIF(!CRichEditView)
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // $$VIEW_CLASS$$ drawing
  115.  
  116. void $$VIEW_CLASS$$::OnDraw(CDC* pDC)
  117. {
  118.     $$DOC_CLASS$$* pDoc = GetDocument();
  119.     ASSERT_VALID(pDoc);
  120. $$IF(VERBOSE)
  121.  
  122.     // TODO: add draw code for native data here
  123. $$IF(CONTAINER || CONTAINER_SERVER)
  124. $$IF(!CRichEditView)
  125.     // TODO: also draw all OLE items in the document
  126. $$ENDIF //!CRichEditView
  127. $$ENDIF //CONTAINERS
  128. $$ENDIF //VERBOSE
  129. $$IF(CONTAINER || CONTAINER_SERVER)
  130. $$IF(!CRichEditView)
  131.  
  132.     // Draw the selection at an arbitrary position.  This code should be
  133.     //  removed once your real drawing code is implemented.  This position
  134.     //  corresponds exactly to the rectangle returned by $$CNTRITEM_CLASS$$,
  135.     //  to give the effect of in-place editing.
  136.  
  137.     // TODO: remove this code when final draw code is complete.
  138.  
  139.     if (m_pSelection == NULL)
  140.     {
  141.         POSITION pos = pDoc->GetStartPosition();
  142.         m_pSelection = ($$CNTRITEM_CLASS$$*)pDoc->GetNextClientItem(pos);
  143.     }
  144.     if (m_pSelection != NULL)
  145.         m_pSelection->Draw(pDC, CRect(10, 10, 210, 210));
  146. $$ENDIF //!CRichEditView
  147. $$ENDIF //CONTAINERS
  148. }
  149. $$ENDIF // !(CFormView || CRecordView || CDaoRecordView)
  150. $$IF(CScrollView || CONTAINER || CONTAINER_SERVER || CRecordView || CDaoRecordView || CListView || CTreeView)
  151.  
  152. void $$VIEW_CLASS$$::OnInitialUpdate()
  153. {
  154. $$IF(CRecordView || CDaoRecordView)
  155.     m_pSet = &GetDocument()->$$RECSET_VARIABLE$$;
  156. $$ENDIF
  157.     $$VIEW_BASE_CLASS$$::OnInitialUpdate();
  158. $$IF(VERBOSE)
  159. $$IF(CListView)
  160.  
  161.     // TODO: You may populate your ListView with items by directly accessing
  162.     //  its list control through a call to GetListCtrl().
  163. $$ELIF(CTreeView)
  164.  
  165.     // TODO: You may populate your TreeView with items by directly accessing
  166.     //  its tree control through a call to GetTreeCtrl().
  167. $$ENDIF //Views
  168. $$ENDIF //VERBOSE
  169. $$IF(CONTAINER || CONTAINER_SERVER)
  170. $$IF(!CRichEditView)
  171.  
  172. $$IF(VERBOSE)
  173.     // TODO: remove this code when final selection model code is written
  174. $$ENDIF //VERBOSE
  175.     m_pSelection = NULL;    // initialize selection
  176.  
  177. $$ENDIF //!CRichEditView
  178. $$IF(CRichEditView)
  179.  
  180. $$IF(VERBOSE)
  181.     // Set the printing margins (720 twips = 1/2 inch).
  182. $$ENDIF //VERBOSE
  183.     SetMargins(CRect(720, 720, 720, 720));
  184. $$ENDIF    //CRichEditView
  185. $$ENDIF //CONTAINERS
  186. $$IF(CScrollView)
  187.     CSize sizeTotal;
  188. $$IF(VERBOSE)
  189.     // TODO: calculate the total size of this view
  190. $$ENDIF
  191.     sizeTotal.cx = sizeTotal.cy = 100;
  192.     SetScrollSizes(MM_TEXT, sizeTotal);
  193. $$ENDIF
  194. }
  195. $$ENDIF // CScrollView || CONTAINER || CONTAINER_SERVER || CRecordView || CDaoRecordView
  196. $$IF(PRINT)
  197.  
  198. /////////////////////////////////////////////////////////////////////////////
  199. // $$VIEW_CLASS$$ printing
  200.  
  201. BOOL $$VIEW_CLASS$$::OnPreparePrinting(CPrintInfo* pInfo)
  202. {
  203. $$IF(CEditView)
  204.     // default CEditView preparation
  205.     return CEditView::OnPreparePrinting(pInfo);
  206. $$ELSE
  207.     // default preparation
  208.     return DoPreparePrinting(pInfo);
  209. $$ENDIF
  210. }
  211.  
  212. $$IF(!CRichEditView)
  213. $$IF(CEditView)
  214. void $$VIEW_CLASS$$::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  215. $$ELSE
  216. void $$VIEW_CLASS$$::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  217. $$ENDIF //CEditView
  218. {
  219. $$IF(CEditView)
  220. $$IF(VERBOSE)
  221.     // Default CEditView begin printing.
  222. $$ENDIF //VERBOSE
  223.     CEditView::OnBeginPrinting(pDC, pInfo);
  224. $$ELSE
  225. $$IF(VERBOSE)
  226.     // TODO: add extra initialization before printing
  227. $$ENDIF //VERBOSE
  228. $$ENDIF //CEditView
  229. }
  230.  
  231. $$IF(CEditView)
  232. void $$VIEW_CLASS$$::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
  233. $$ELSE
  234. void $$VIEW_CLASS$$::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  235. $$ENDIF //CEditView
  236. {
  237. $$IF(CEditView)
  238. $$IF(VERBOSE)
  239.     // Default CEditView end printing
  240. $$ENDIF //VERBOSE
  241.     CEditView::OnEndPrinting(pDC, pInfo);
  242. $$ELSE
  243. $$IF(VERBOSE)
  244.     // TODO: add cleanup after printing
  245. $$ENDIF //VERBOSE
  246. $$ENDIF //CEditView
  247. }
  248. $$ENDIF //!CRichEditView
  249. $$IF(CFormView)
  250.  
  251. void $$VIEW_CLASS$$::OnPrint(CDC* pDC, CPrintInfo*)
  252. {
  253. $$IF(VERBOSE)
  254.     // TODO: add code to print the controls
  255. $$ENDIF
  256. }
  257. $$ENDIF //CFormView
  258. $$ENDIF //PRINT
  259. $$IF(CONTAINER || CONTAINER_SERVER)
  260. $$IF(!CRichEditView)
  261.  
  262. /////////////////////////////////////////////////////////////////////////////
  263. // OLE Client support and commands
  264.  
  265. BOOL $$VIEW_CLASS$$::IsSelected(const CObject* pDocItem) const
  266. {
  267. $$IF(VERBOSE)
  268.     // The implementation below is adequate if your selection consists of
  269.     //  only $$CNTRITEM_CLASS$$ objects.  To handle different selection
  270.     //  mechanisms, the implementation here should be replaced.
  271.  
  272.     // TODO: implement this function that tests for a selected OLE client item
  273.  
  274. $$ENDIF
  275.     return pDocItem == m_pSelection;
  276. }
  277.  
  278. void $$VIEW_CLASS$$::OnInsertObject()
  279. {
  280. $$IF(VERBOSE)
  281.     // Invoke the standard Insert Object dialog box to obtain information
  282.     //  for new $$CNTRITEM_CLASS$$ object.
  283. $$ENDIF
  284.     COleInsertDialog dlg;
  285.     if (dlg.DoModal() != IDOK)
  286.         return;
  287.  
  288.     BeginWaitCursor();
  289.  
  290.     $$CNTRITEM_CLASS$$* pItem = NULL;
  291.     TRY
  292.     {
  293. $$IF(VERBOSE)
  294.         // Create new item connected to this document.
  295. $$ENDIF
  296.         $$DOC_CLASS$$* pDoc = GetDocument();
  297.         ASSERT_VALID(pDoc);
  298.         pItem = new $$CNTRITEM_CLASS$$(pDoc);
  299.         ASSERT_VALID(pItem);
  300.  
  301. $$IF(VERBOSE)
  302.         // Initialize the item from the dialog data.
  303. $$ENDIF
  304.         if (!dlg.CreateItem(pItem))
  305.             AfxThrowMemoryException();  // any exception will do
  306.         ASSERT_VALID(pItem);
  307.  
  308. $$IF(VERBOSE)
  309.         // If item created from class list (not from file) then launch
  310.         //  the server to edit the item.
  311. $$ENDIF
  312.         if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
  313.             pItem->DoVerb(OLEIVERB_SHOW, this);
  314.  
  315.         ASSERT_VALID(pItem);
  316. $$IF(VERBOSE)
  317.  
  318.         // As an arbitrary user interface design, this sets the selection
  319.         //  to the last item inserted.
  320.  
  321.         // TODO: reimplement selection as appropriate for your application
  322. $$ENDIF
  323.  
  324.         m_pSelection = pItem;   // set selection to last inserted item
  325.         pDoc->UpdateAllViews(NULL);
  326.     }
  327.     CATCH(CException, e)
  328.     {
  329.         if (pItem != NULL)
  330.         {
  331.             ASSERT_VALID(pItem);
  332.             pItem->Delete();
  333.         }
  334.         AfxMessageBox(IDP_FAILED_TO_CREATE);
  335.     }
  336.     END_CATCH
  337.  
  338.     EndWaitCursor();
  339. }
  340.  
  341. $$IF(VERBOSE)
  342. // The following command handler provides the standard keyboard
  343. //  user interface to cancel an in-place editing session.  Here,
  344. //  the container (not the server) causes the deactivation.
  345. $$ENDIF
  346. void $$VIEW_CLASS$$::OnCancelEditCntr()
  347. {
  348.     // Close any in-place active item on this view.
  349.     COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  350.     if (pActiveItem != NULL)
  351.     {
  352.         pActiveItem->Close();
  353.     }
  354.     ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  355. }
  356.  
  357. $$IF(VERBOSE)
  358. // Special handling of OnSetFocus and OnSize are required for a container
  359. //  when an object is being edited in-place.
  360. $$ENDIF
  361. void $$VIEW_CLASS$$::OnSetFocus(CWnd* pOldWnd)
  362. {
  363.     COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  364.     if (pActiveItem != NULL &&
  365.         pActiveItem->GetItemState() == COleClientItem::activeUIState)
  366.     {
  367.         // need to set focus to this item if it is in the same view
  368.         CWnd* pWnd = pActiveItem->GetInPlaceWindow();
  369.         if (pWnd != NULL)
  370.         {
  371.             pWnd->SetFocus();   // don't call the base class
  372.             return;
  373.         }
  374.     }
  375.  
  376.     $$VIEW_BASE_CLASS$$::OnSetFocus(pOldWnd);
  377. }
  378.  
  379. void $$VIEW_CLASS$$::OnSize(UINT nType, int cx, int cy)
  380. {
  381.     $$VIEW_BASE_CLASS$$::OnSize(nType, cx, cy);
  382.     COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  383.     if (pActiveItem != NULL)
  384.         pActiveItem->SetItemRects();
  385. }
  386. $$ENDIF //!CRichEditView
  387. $$ENDIF //CONTAINER || CONTAINER_SERVER
  388. $$IF(MINI_SERVER || FULL_SERVER || CONTAINER_SERVER)
  389.  
  390. /////////////////////////////////////////////////////////////////////////////
  391. // OLE Server support
  392.  
  393. $$IF(VERBOSE)
  394. // The following command handler provides the standard keyboard
  395. //  user interface to cancel an in-place editing session.  Here,
  396. //  the server (not the container) causes the deactivation.
  397. $$ENDIF
  398. void $$VIEW_CLASS$$::OnCancelEditSrvr()
  399. {
  400.     GetDocument()->OnDeactivateUI(FALSE);
  401. }
  402. $$ENDIF //SERVERS
  403.  
  404. /////////////////////////////////////////////////////////////////////////////
  405. // $$VIEW_CLASS$$ diagnostics
  406.  
  407. #ifdef _DEBUG
  408. void $$VIEW_CLASS$$::AssertValid() const
  409. {
  410.     $$VIEW_BASE_CLASS$$::AssertValid();
  411. }
  412.  
  413. void $$VIEW_CLASS$$::Dump(CDumpContext& dc) const
  414. {
  415.     $$VIEW_BASE_CLASS$$::Dump(dc);
  416. }
  417.  
  418. $$DOC_CLASS$$* $$VIEW_CLASS$$::GetDocument() // non-debug version is inline
  419. {
  420.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS($$DOC_CLASS$$)));
  421.     return ($$DOC_CLASS$$*)m_pDocument;
  422. }
  423. #endif //_DEBUG
  424. $$IF(CRecordView || CDaoRecordView)
  425.  
  426. /////////////////////////////////////////////////////////////////////////////
  427. // $$VIEW_CLASS$$ database support
  428. $$IF(CRecordView)
  429. CRecordset* $$VIEW_CLASS$$::OnGetRecordset()
  430. $$ELSE 
  431. CDaoRecordset* $$VIEW_CLASS$$::OnGetRecordset()
  432. $$ENDIF
  433. {
  434.     return m_pSet;
  435. }
  436.  
  437. $$ENDIF //CRecordView || CDaoRecordView
  438.  
  439. /////////////////////////////////////////////////////////////////////////////
  440. // $$VIEW_CLASS$$ message handlers
  441.